package pl.com.kyhu.dietex3000.GUI.charts;

import javax.swing.JFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class XYAreaChart extends JFrame {

	private static final long serialVersionUID = 1L;
	
	XYSeriesCollection dataset;
	JFreeChart chart;

	String chartTitle;
	String xLabel;
	String yLabel;

	public XYAreaChart(String chartTitle, String xLabel, String yLabel, Integer chartType) {
		super(chartTitle);
		this.chartTitle = chartTitle;
		this.xLabel = xLabel;
		this.yLabel = yLabel;
		this.dataset = new XYSeriesCollection();
		switch(chartType){
		case 1:
			this.chart = ChartFactory.createXYAreaChart(chartTitle, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false);
			break;
		case 2:
			this.chart = ChartFactory.createXYLineChart(chartTitle, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false);
			break;
		}

		
		ChartPanel chartPanel = new ChartPanel(chart);
		chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));		
		setContentPane(chartPanel);

	}
	
	public void addSeries(XYSeries series){
		dataset.addSeries(series);	
		createChart();
	}
	
	public void createChart(){
		chart = ChartFactory.createXYAreaChart(chartTitle, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false);
	}

}
